﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LastfmNet.Models
{
    public class HypedTrack : LastfmModelBase, ITrack, IHyped, IHasFourImages
    {
        public HypedTrack()
        {
            this.Name = string.Empty;
            this.Duration = 0;
            this.PercentageChange = 0;
            this.Mbid = string.Empty;
            this.Url = string.Empty;
            this.Streamable = false;
            this.StreamableFulltrack = false;
            this.Artist = new TrackArtist();
            this.ImageSmall = string.Empty;
            this.ImageMedium = string.Empty;
            this.ImageLarge = string.Empty;
            this.ImageExtraLarge = string.Empty;
        }

        public HypedTrack(XmlNode hypedTrackNode)
        {
            if (hypedTrackNode == null) return;
            this.InitializeFromXmlNode(hypedTrackNode);
        }

        public override void InitializeFromXmlNode(XmlNode node)
        {
            if (node == null) return;
            this.Name = node.GetChildValue("name");
            this.Duration = node.GetChildValue("duration").ToInteger();
            this.PercentageChange = node.GetChildValue("percentagechange").ToInteger();
            this.Mbid = node.GetChildValue("mbid");
            this.Url = node.GetChildValue("url");
            this.Streamable = node.GetChildValue("streamable").ToBoolean();
            this.StreamableFulltrack = node.GetChild("streamable").GetAttributeValue("fulltrack").ToBoolean();
            this.Artist = new TrackArtist(node.GetChild("artist"));
            this.ImageSmall = node.GetChildValueWithSpecialAtrribute("image", "size", "small");
            this.ImageMedium = node.GetChildValueWithSpecialAtrribute("image", "size", "medium");
            this.ImageLarge = node.GetChildValueWithSpecialAtrribute("image", "size", "large");
            this.ImageExtraLarge = node.GetChildValueWithSpecialAtrribute("image", "size", "extralarge");
        }

        public string Name
        {
            get;
            set;
        }

        public int Duration
        {
            get;
            set;
        }

        public string Mbid
        {
            get;
            set;
        }

        public string Url
        {
            get;
            set;
        }

        public bool Streamable
        {
            get;
            set;
        }

        public bool StreamableFulltrack
        {
            get;
            set;
        }

        public TrackArtist Artist
        {
            get;
            set;
        }

        public string ImageSmall
        {
            get;
            set;
        }

        public string ImageMedium
        {
            get;
            set;
        }

        public string ImageLarge
        {
            get;
            set;
        }

        public string ImageExtraLarge
        {
            get;
            set;
        }

        public int PercentageChange
        {
            get;
            set;
        }
    }
}
